import { observable, action } from 'mobx';
import { message } from 'antd';
import { ListStore } from './listStore'
import { WeaTableNew } from 'comsMobx';
import * as API_Journal from '../apis/journal';
const { TableStore } = WeaTableNew;
/**
 * 刊物Store
 */
export default class JournalStore extends ListStore {

    @observable kwlx = '0';

    @observable tableStore1 = new TableStore();

    @observable isShowShare = false;

    initList = (params) =>{
        this.kwlx = params.kwlx;
        API_Journal.getJournalList({...params,state:0}).then(data => {
            this.tableStore = new TableStore();
            this.tableStore.getDatas(data.sessionkey);
        })
        API_Journal.getJournalList({...params,state:1}).then(data => {
            this.tableStore1 = new TableStore();
            this.tableStore1.getDatas(data.sessionkey);
        })
    }

    addJournal = () =>{
        API_Journal.addJournal({kwlx:this.kwlx}).then(data => {
            this.initList({kwlx:this.kwlx});
            window.open("/spa/cpt/index.html#/main/cpt/JournalEdit?kwid="+data.kwid, "_blank");
        })
    }

    dingkan = () =>{
        API_Journal.journalOperation({type:'dingkan',ids:this.tableStore.selectedRowKeysAllPages}).then(data => {
            this.initList({kwlx:this.kwlx});
        })
    }

    batchDelete = () =>{
        API_Journal.journalOperation({type:'batchDelete',ids:this.tableStore.selectedRowKeysAllPages}).then(data => {
            this.initList({kwlx:this.kwlx});
        })
    }

    resume = () =>{
        API_Journal.journalOperation({type:'resume',ids:this.tableStore1.selectedRowKeysAllPages}).then(data => {
            this.initList({kwlx:this.kwlx});
        })
    }

    //刷新列表
    @action
    reLoad = () => {
        this.tableStore.getDatas(this.tableStore.dataKey, this.tableStore.current, this.tableStore.pageSize, this.tableStore.sortParams);
        this.tableStore1.getDatas(this.tableStore1.dataKey, this.tableStore1.current, this.tableStore1.pageSize, this.tableStore1.sortParams);
    }

    showAddShareModal = (v) => {
        this.isShowShare = v;
    }

    publish = (params) =>{
        API_Journal.journalOperation({type:'publish',ids:this.tableStore1.selectedRowKeysAllPages,...params}).then(data => {
            if(data.success){
                API_Journal.getJournalList({...params,state:1}).then(data => {
                    this.tableStore1 = new TableStore();
                    this.tableStore1.getDatas(data.sessionkey);
                })
                message.success(data.msg);
            }else{
                message.error('发布失败');
            }
            this.isShowShare = false;
        })
        console.log(params);
    }

    cancelPublish = (params) =>{
        API_Journal.journalOperation({type:'cancelPublish',ids:this.tableStore1.selectedRowKeysAllPages,...params}).then(data => {
            if(data.success){
                API_Journal.getJournalList({...params,state:1}).then(data => {
                    this.tableStore1 = new TableStore();
                    this.tableStore1.getDatas(data.sessionkey);
                })
                message.success(data.msg);
            }else{
                message.error('取消失败');
            }
        })
    }

}
